package com.heyqing.topic.AddStrings_0415;

/**
 * ClassName:AddStrings
 * Package:com.heyqing.topic.AddStrings_0415
 * Description:
 *
 * @Date:2024/9/29
 * @Author:Heyqing
 */
public class AddStrings {
    public String addStrings(String num1, String num2) {
        int flag = 0;
        StringBuilder sb = new StringBuilder();
        StringBuilder sbn1 = new StringBuilder(num1);
        num1 = sbn1.reverse().toString();
        StringBuilder sbn2 = new StringBuilder(num2);
        num2 = sbn2.reverse().toString();
        for (int i = 0; i < Math.max(num1.length(), num2.length()); i++) {
            int n1 = 0, n2 = 0;
            if (i <= num1.length() - 1) {
                n1 = num1.charAt(i) - 48;
            }
            if (i <= num2.length() - 1) {
                n2 = num2.charAt(i) - 48;
            }
            int temp = n1 + n2 + flag;
            flag = temp / 10;
            sb.append(temp % 10);
        }
        if (flag == 1) sb.append(1);
        return sb.reverse().toString();
    }
}
